package com.qdu.reducer;

import com.qdu.bean.temp_atempBean;
import com.qdu.bean.year_seasonBean;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.text.DecimalFormat;

public class tempByYear_SeasonReducer extends Reducer<year_seasonBean, temp_atempBean,year_seasonBean, temp_atempBean> {


    temp_atempBean  ta=new temp_atempBean();

    @Override
    protected void reduce(year_seasonBean key, Iterable<temp_atempBean> values, Context context) throws IOException, InterruptedException {
        double  temp=0;
        double  atemp=0;
        int sum=0;
        DecimalFormat df=new DecimalFormat("0.00");

        for (temp_atempBean t : values) {
            temp+=t.getTemp();
            atemp+=t.getAtemp();
            sum++;
        }
        double temp1=Double.parseDouble(df.format(temp/sum));
        double atemp1=Double.parseDouble(df.format(atemp/sum));

        ta.set(temp1,atemp1);

        context.write(key,ta);
    }
}
